#include "HiredisOptionsBuilder.h"

#include <cassert>
#include <memory>

#define GLOG_USE_GLOG_EXPORT
#include <glog/logging.h>

HiredisOptionsBuilder::HiredisOptionsBuilder() : m_ipaddr(""), m_port(6379), m_timeout(nullptr)
{
}

HiredisOptionsBuilder::~HiredisOptionsBuilder()
{
}

void HiredisOptionsBuilder::setTcpHost(const char *ip, const uint16_t &port)
{
    m_ipaddr = ip;
    m_port   = port;
}

void HiredisOptionsBuilder::setConnectTimeout(const struct timeval &&timeout)
{
    m_timeout  = new timeval;
    *m_timeout = timeout;
}

std::shared_ptr<redisOptions> HiredisOptionsBuilder::buildRedisOptions()
{
    assert(!m_ipaddr.empty());

    redisOptions *opts = new redisOptions;
    REDIS_OPTIONS_SET_TCP(opts, m_ipaddr.c_str(), m_port);
    opts->connect_timeout = m_timeout;
    return std::shared_ptr<redisOptions>(opts);
}